%% OBJECTIVE FUNCTION IN LIMITED-COMMITMENT CONTRACT
function o = limited_fun(p, x, z, v, vx_f, vx_b, vx_c, vxx, params)
%% parameters
temp = num2cell(params);
[rho, r, ra, alpha, sigma, lambda, M, eta_min, eta_max] = temp{:};

%% Objective
C = p(:,1);
B = p(:,2);
Eta = p(:,3);

ExRet = sigma.*Eta.*x;
K = (B - Eta.*z).*C.^rho./(sigma*lambda);

o = C - ExRet.*K + ...
        v.* ( ra - C.^(1-rho)./(1-rho) + 0.5.*rho*B.^2) +...
        0.5.*Eta.^2*x^2*(1-x)^2.*vxx +...
        vx_c.*Eta.*x.*(1-x).*B;
    
   


end